package jmine.tec.web.servlet.cipher;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jmine.tec.utils.Tuple;

/**
 * Implementa o protocolo de comunicacao segura do lado do servidor. Eh usado em conjunto com um Filtro
 * 
 * @author takeshi
 */
public interface SecureCommunicationHandler {

    /**
     * Decora o request e o response, devolvendo implementacoes capazes de lidar com o protocolo especifico
     * 
     * @param request o {@link HttpServletRequest} a ser decorado
     * @param response o {@link HttpServletResponse} a ser decorado
     * @return {@link Tuple} com o request e o response
     * @throws IOException e
     */
    Tuple<HttpServletRequest, HttpServletResponse> wrapRequestResponse(HttpServletRequest request, HttpServletResponse response)
            throws IOException;

    /**
     * Se true, o filtro pode proceder com o processamento do request
     * 
     * @param httpRequest {@link HttpServletRequest}
     * @param httpResponse {@link HttpServletResponse}
     * @return boolean
     */
    boolean proceedRequest(HttpServletRequest httpRequest, HttpServletResponse httpResponse);

    /**
     * Devolve o proximo estagio que deve ser executado
     * 
     * @param httpRequest {@link HttpServletRequest}
     * @param httpResponse {@link HttpServletResponse}
     * @return {@link SecureCommunicationHandler}
     * @throws IOException e
     */
    SecureCommunicationHandler nextStage(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException;

}
